<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出差审批')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-businessTrip" class="form-horizontal">
        <input name="dept.deptId" type="hidden" th:value="${businessTrip.dept.deptId}" id="treeId"/>
        <input name="user.userId" type="hidden" th:value="${businessTrip.user.userId}" id="userIdSelect"/>

        <input name="id" type="hidden" th:value="${businessTrip.id}"/>
        <input name="act.taskId" type="hidden" th:value="${businessTrip.act.taskId}"/>
        <input name="act.taskName" type="hidden" th:value="${businessTrip.act.taskName}"/>
        <input name="act.taskDefKey" type="hidden" th:value="${businessTrip.act.taskDefKey}"/>
        <input name="act.procInsId" type="hidden" th:value="${businessTrip.act.procInsId}"/>
        <input name="act.procDefId" type="hidden" th:value="${businessTrip.act.procDefId}"/>
        <input name="act.flag" type="hidden" th:value="${businessTrip.act.flag}" id="flag"/>

        <h4 class="form-header h4">[[${businessTrip.act.taskName}]]：审批</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: #f70404; ">*</span>姓名：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="请输入用户名称" id="userSuggest"
                                   th:value="${businessTrip.user.userName}" readonly="readonly" maxlength="20" required>
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属部门：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="dept.deptName" id="treeName" type="text" th:value="${businessTrip.dept.deptName}"
                                   readonly="readonly" placeholder="请选择归属部门" class="form-control" required>
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">性别：</label>
                    <div class="col-sm-8">
                        <select name="gender" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}" disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}" th:field="*{businessTrip.user.sex}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">岗位：</label>
                    <div class="col-sm-8">
                        <input name="post" placeholder="请输入岗位" class="form-control" th:value="${businessTrip.post}"
                               readonly="readonly" type="text" maxlength="10" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">出差开始时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input name="startTime" type="text" class="form-control" id="startTime"
                                   th:value="${#dates.format(businessTrip.startTime, 'yyyy-MM-dd HH:mm:ss')}" readonly="readonly"
                                   placeholder="yyyy-MM-dd HH:mm:ss" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">出差结束时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input name="endTime" type="text" class="form-control" id="endTime"
                                   th:value="${#dates.format(businessTrip.endTime, 'yyyy-MM-dd HH:mm:ss')}" readonly="readonly"
                                   placeholder="yyyy-MM-dd HH:mm:ss" required>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--出差类型-->
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>出差类型：</label>
                    <div class="col-sm-8">
                        <select name="businessTripType" class="form-control m-b" th:with="type=${@dict.getType('businessTrip_type')}" required disabled>
                            <option value="${businessTrip.businessTripType}">--请选择出差类型--</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}" th:field="*{businessTrip.businessTripType}"></option>
                            <!--等效-->
                            <!--                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
                            <!--                                    th:value="${dict.dictValue}" th:if="${dict.dictValue}==${businessTrip.businessTripType}" selected></option>-->
                            <!--                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
                            <!--                                    th:value="${dict.dictValue}" th:if="${dict.dictValue}!=${businessTrip.businessTripType}"></option>-->
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-sm-6" th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit')&& not #strings.contains(businessTrip.act.taskDefKey,'modifyApply')&& not #strings.contains(businessTrip.act.taskDefKey,'ceoAudit')}">
                <div class="form-group">
                    <!--根据不同的任务让用户选择不同的审批人-->
                    <label class="col-sm-4 control-label" th:if="${#strings.contains(businessTrip.act.taskDefKey,'deptAudit')}"><span style="color: red; ">*</span>选择总经理审批：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input class="form-control" type="text" name="auditUserName" id="userNames"  onclick="selectUsersToParentCallBack2()" required th:value="${businessTrip.auditUserName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            <input class="form-control" type="hidden" name="auditUserId" id="chooseLeader" th:value="${businessTrip.auditUserId}">
                        </div>

                    </div>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">请假原因：</label>
                    <div class="col-xs-10">
                        <textarea name="content" maxlength="500" th:text="${businessTrip.content}" readonly="readonly"
                                  class="form-control" rows="3" required="required"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">其它信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="remarks" maxlength="500" th:text="${businessTrip.remarks}" readonly="readonly"
                                  class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4"
            th:if="${not #strings.isEmpty(businessTrip.deptText) || not #strings.isEmpty(businessTrip.hrText) || not #strings.isEmpty(businessTrip.zjlText)}">
            审批信息</h4>
        <div class="row" th:if="${not #strings.isEmpty(businessTrip.deptText)}">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label"><span  style="color: red; " > *</span>部门经理意见：</label>
                    <div class="col-xs-10">
                        <textarea name="deptText" maxlength="500" th:text="${businessTrip.deptText}" readonly="readonly"
                                  class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" th:if="${not #strings.isEmpty(businessTrip.zjlText)}">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label"><span  style="color: red; " > *</span>总经理意见：</label>
                    <div class="col-xs-10">
                        <textarea name="zjlText" maxlength="500" th:text="${businessTrip.zjlText}" readonly="readonly"
                                  class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4" th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit')}"><span  style="color: blue; " > *</span>审批意见</h4>
        <div class="row" th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit')}">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label"><span  style="color: red; " > *</span>您的意见：</label>
                    <div class="col-xs-10">
                        <textarea name="act.comment" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" shiro:hasAllPermissions="'activiti:businessTripAudit:edit'">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-success" onclick="xiaojia()"
                        th:if="${#strings.contains(businessTrip.act.taskDefKey,'tripAudit')}"><i class="fa fa-check"></i>出差核销
                </button>&nbsp;

                <button type="button" class="btn btn-sm btn-success" onclick="consent()"
                        th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit')}"><i class="fa fa-check"></i>同意
                </button>&nbsp;
                <button type="button" class="btn btn-sm btn-success" onclick="reject()"
                        th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit')}"><i class="fa fa-check"></i>驳 回
                </button>
            </div>
            <!--提示信息-->
            <div class="col-sm-offset-5 col-sm-10">
                <i class="fa fa-tag" style="color: green; " th:if="${not #strings.contains(businessTrip.act.taskDefKey,'tripAudit') && not #strings.contains(businessTrip.act.taskDefKey,'ceoAudit')}"><span  style="color: blue; " > 温馨提示：</span>  <span style="color: red; " > 提交处理意见前请选选择审批人，并填写处理意见！</span></i>
                <i class="fa fa-tag" style="color: green; " th:if="${#strings.contains(businessTrip.act.taskDefKey,'ceoAudit')}"><span  style="color: blue; " > 温馨提示：</span>  <span style="color: red; " > 提交处理意见前请先填写处理意见！</span></i>
            </div>
        </div>
        <h4 class="form-header h4">流转信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "activiti/task";
    var prefix2 = ctx + "oa/businessTrip";
    var prefix3=ctx + "activiti/process";
    // var deptId=1;
    function selectUsersToParentCallBack2(){
        var options = {
            title: '选择部审批人',
            url: prefix3 + "/chooseAuditUser/",
            width: 1360,

            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        var userNames = layero.find("iframe")[0].contentWindow.getSelections2();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $('#chooseLeader').val( rows.join());
        $('#userNames').val(userNames.join());
        $.modal.close(index);
    }

    $(function () {
        queryHistoicFlowList();
    })

    /*流转历史信息*/
    function queryHistoicFlowList() {
        var options = {
            url: prefix + "/histoicFlow",
            /*是否显示分页*/
            pagination:false,
            /*是否显示刷新按钮*/
            showSearch:false,
            /*是否显示详细视图和列表视图的切换按钮*/
            showToggle:false,
            showColumns:false,
            showRefresh:false,
            search:false,
            columns: [
                {
                    field: 'histIns.activityName',
                    title: '执行环节'
                },
                {
                    field: 'sssigneeName',
                    title: '执行人'
                },
                {
                    field: 'histIns.startTime',
                    title: '开始时间'
                },
                {
                    field: 'histIns.endTime',
                    title: '结束时间'
                },
                {
                    field: 'comment',
                    title: '提交意见'
                },
                {
                    field: 'taskFor',
                    title: '任务历时'
                }]
        };
        $.table.init(options);
    }

    //同意
    function consent() {
        $("#flag").val('yes');
        var url = prefix2 + "/saveBusinessTripAudit";
        if ($.validate.form()) {
            var data = $("#form-businessTrip").serializeArray();
            console.log("data:",data);
            $.operate.post(url, data, function (result) {
                if (result.code != '0') {
                    return;
                }
                window.parent.location.reload(); //刷新父页面
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);  // 关闭layer
            });
        }
    }

    //驳回
    function reject() {
        $("#flag").val('no')
        var url = prefix2 + "/saveBusinessTripAudit";
        if ($.validate.form()) {
            var data = $("#form-businessTrip").serializeArray();
            $.operate.post(url, data, function (result) {
                if (result.code != '0') {
                    return;
                }
                window.parent.location.reload(); //刷新父页面
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);  // 关闭layer
            });
        }
    }

    //销假
    function xiaojia() {
        $("#flag").val('yes');
        var url = prefix2 + "/saveBusinessTripAudit";
        if ($.validate.form()) {
            var data = $("#form-businessTrip").serializeArray();
            $.operate.post(url, data, function (result) {
                window.parent.location.reload(); //刷新父页面
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);  // 关闭layer
            });
        }
    }

    $("#form-businessTrip").validate({
        onkeyup: false,
        rules: {
            loginName: {
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: prefix + "/checkLoginNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        name: function () {
                            return $.common.trim($("#loginName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            password: {
                minlength: 3,
                maxlength: 20
            },
        },
        messages: {
            "loginName": {
                remote: "用户已经存在"
            },
        },
        focusCleanup: true
    });

    /*选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    }

</script>
</body>
</html>
